<template>
    <view class="Commissioned" :style="{ height: ISIphone ? '96vh' : '100vh' }">
        <view class="top">
            <img style="width: 80%; margin: 0 auto"
                src="https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/YPC/11.png" />
            <p>
                <span style="
            width: 31%;
            display: inline-block;
            text-align: left;
            padding-left: 0%;
          ">鉴定申请</span>
                <span style="width: 31%; display: inline-block; text-align: center">合同签订</span>
                <span style="
            width: 31%;
            display: inline-block;
            text-align: center;
            padding-left: 12%;
          ">房屋整治</span>
            </p>
        </view>
        <view class="backgrounds"></view>
        <view class="list">
            <!--<view>-->
            <!--<span style="color: #ff0000">*</span><span>请拍摄并上传申请人的有效身份证</span>-->
            <!--<view style="display: flex; justify-content: space-between;padding: .6rem; 0">-->
            <!--<view>-->
            <!--<u-upload :fileList="fileList6" @afterRead="afterRead" @delete="deletePic" @clickPreview="clickPreview"-->
            <!--name="6" multiple :maxCount="1" width="320rpx" height="200rpx">-->
            <!--<image src="https://cdn.uviewui.com/uview/demo/upload/positive.png" mode="widthFix"-->
            <!--style="width: 320rpx; height: 300rpx"></image>-->
            <!--</u-upload>-->
            <!--</view>-->
            <!--<view>-->
            <!--<u-upload :fileList="fileList7" @afterRead="afterRead1" @delete="deletePic1" name="7" accept="image"-->
            <!--multiple :maxCount="1" width="320rpx" height="200rpx">-->
            <!--<image src="https://cdn.uviewui.com/uview/demo/upload/positive.png" mode="widthFix"-->
            <!--style="width: 320rpx; height: 300rpx"></image>-->
            <!--</u-upload>-->
            <!--</view>-->
            <!--</view>-->
            <!--</view>-->
            <view v-for="(item, index) in ListData" :key="index">
                <!-- 注意，如果需要兼容微信小程序，最好通过setRules方法设置rules规则 -->
                <view v-if="item.title" class="title">
                    <span>{{ item.name }}</span>
                    <span v-if="item.name == '基本信息'" style="color: #d2d2d2; font-size: 0.8rem; float: right">{{
                        item.rightName
                    }}</span>
                    <span v-else v-show="ISSSowSpan" @click="handleGethouseData"
                        style="color: dodgerblue; font-size: 0.8rem; float: right">{{ item.rightName }}</span>
                </view>
                <u-form labelPosition="left" :model="model1" ref="form1" :rules="rules" v-else>
                    <u-form-item :label="item.name" labelWidth="200" :prop="item.key" borderBottom :required="item.required"
                        ref="item1" v-if="!item.XIALA">
                        <u-input :placeholder="'请输入' + item.name" :disabled="item.disabled" v-model="model1[item.key]" border="none"></u-input>
                    </u-form-item>
                    <u-form-item :label="item.name" labelWidth="200" :required="item.required" v-else :prop="item.key"
                        borderBottom @click="
                            item.name == '鉴定机构' ? handlegoto() : '';
                        XIALADATA[item.keys] = true;
                        confirmData(item.name)
                            " ref="item1">
                        <u-input :placeholder="'请输入' + item.name" v-model="model1[item.key]" :disabled="item.disabled"
                            disabledColor="#ffffff" border="none"></u-input>
                        <u-icon slot="right" name="arrow-right"></u-icon>
                    </u-form-item>
                </u-form>
                <!-- <u-action-sheet
          :show="XIALADATA[item.keys]"
          :actions="item.actions"
          :title="'请选择' + item.name"
          @close="XIALADATA[item.keys] = false"
          @select="sexSelect"
          keyName="cityname"
        >
        </u-action-sheet> -->
                <u-picker @closeOnClickOverlay="true" :show="XIALADATA[item.keys]" :columns="item.actions" @change="change"
                    @cancel="cancel(item.keys)" @confirm="confirm" :keyName="item.keyName">
                </u-picker>
            </view>
            <view class="title"> 材料上传 </view>
            <view>
                <u-cell-group>
                    <u-cell size="large" title="材料文件" :value="FILENAME" label="支持pdf\word等文件格式上传"></u-cell>
                    <u-upload @afterRead="afterRead" accept="pdf" @delete="deletePic" :previewImage="false"
                        :fileList="fileList6" name="6" multiple :maxCount="1" width="100">
                        <view style="position: absolute; right: 0; top: 1.7rem">
                            <u-button size="small" type="primary" :plain="true" text="上传"></u-button>
                        </view>
                    </u-upload>
                </u-cell-group>
                <u-cell-group>
                    <u-cell size="large" title="材料照片" :value="FILENAME1" label="如果上传了材料文件不必再拍照上传"></u-cell>
                    <view style="padding: 0.6rem">
                        <u-upload @afterRead="afterRead1" accept="image" @delete="deletePic1" :fileList="fileList1" name="1"
                            multiple :maxCount="10" width="320rpx" height="200rpx"></u-upload>
                    </view>
                </u-cell-group>
            </view>
        </view>
        <view class="backgrounds"></view>
        <view class="footer">
            <span>请确保资料真实有效,我们会在第一时间处理您的建房申请</span>
            <u-button @click="handleGotonext" style="width: 96%; margin-top: 1rem" text="发起房屋鉴定申请" size="large"
                color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))"></u-button>
        </view>
        <view>
            <u-toast ref="uToast"></u-toast>
        </view>
        <u-popup :show="show" @close="close" @open="open">
            <view style="padding: 10px;max-height:70vh;overflow-y: auto;">
                <u-search placeholder="请输入坐落地址或项目名称" v-model="address" @search="search"></u-search>
                <view v-for="(item1, index1) in ListDataArr" :key="index1">
                    <view v-for="(item, index) in ListData1" :key="index">
                        <view v-if="item.title" class="title">
                            <span>{{ item.name }}</span>
                            <span v-if="item.name == '房屋鉴定'" style="color: #d2d2d2; font-size: 0.8rem; float: right">{{
                                item.rightName }}</span>
                            <span v-else v-show="ISSSowSpan" @click="selectData(item1)"
                                style="color: dodgerblue; font-size: 0.8rem; float: right">{{ item.rightName }}</span>
                        </view>
                        <!-- 注意，如果需要兼容微信小程序，最好通过setRules方法设置rules规则 -->
                        <u--form labelPosition="left" :model="model1" ref="form1" v-else>
                            <u-form-item :label="item.name" labelWidth="200" :prop="item.key" borderBottom
                                :required="item.required" ref="item1">
                                <u--input :placeholder="'请输入' + item.name" readonly v-model="item1[item.key]"
                                    border="none"></u--input>
                            </u-form-item>
                        </u--form>
                        <u-picker @closeOnClickOverlay="true" :show="XIALADATA[item.keys]" :columns="item.actions"
                            @change="change" @cancel="cancel(item.keys)" @confirm="confirm" :keyName="item.keyName">
                        </u-picker>
                    </view>
                </view>
            </view>
        </u-popup>
    </view>
</template>

<script>
import { isIphoneX } from "@/common/utils/safeLimt.js";
import timeFormat from '@/common/js/timeFormat.js'
import {
    getDatalistForTree,
    ECAOpenDataView,
    ECAinsertDataView,
    ECAFileServerUpload,
    ECAPrepareCreateProcess,
    ECAPrepareLoadWorkflowScript,
    ECAPrepareLoadCreateProcess,
    ECAPlatSendTask,
    ECAExecProcedure,
    getRegister,
    getJdFwxxToJs
} from "@/common/utils/api.js";
import qs from "qs";
export default {
    data () {
        return {
            show: false,
            address: '',
            ISIphone: false,
            showSex: false,
            ISSSowSpan: true,
            FILENAME1: "",
            FILENAME: "",
            fileList6: [],
            fileList1: [],
            uuid: "",
            fileList6: [],
            model1: {
                SQR: "",
                SFZH: "",
                PHONE: "",
                SSS: "",
                SSX: "",
                SSZ: "",
                SSQY: '',
                SSC: "",
                FWDZ: "",
                JZCS: "",
                ZLDZ: '',
                XMMC: '',
                JZMJ: '',
                JGLX: '',
                JZNF: "",
                JTYT: '',
                JZWBH: '',
                ZMC: '',
                JDJGMC: "",
                TYSHXYDM: "",
                CQRHSYR: "",
                WTSY: "",
                IF_KNJT: "",
                FWLX: ""
            },
            fileList7: [],
            ListDataDeep: [],
            model2: {
                SSS: "",
                SHH: "",
                SSX: "",
                SSZ: "",
                SSC: "",
                JZCS: "",
                JZNF: "",
                CQRHSYR: "",
                WTSY: "",
            },
            NowData: "",
            XIALADATA: {
                S: false,
                X: false,
                Z: false,
                C: false,
                JZCS: false,
                JZNF: false,
                CQRHSYR: false,
                showPickerWT: false,
            },
            ListData: [
                {
                    name: "申请人信息",
                    rightName: "请核对您的身份信息",
                    title: true,
                },
                // {
                //   name: "产权人使用人",
                //   key: "CQRHSYR",
                //   title: false,
                //   XIALA: true,
                //   keyName: "DICNAME",
                //   required: true,
                //   keys: "CQRHSYR",
                //   actions: [
                //     [
                //       {
                //         DICNAME: "产权人",
                //         DICID: "289",
                //         key: "CQRHSYR",
                //         keys: "CQRHSYR",
                //       },
                //       {
                //         DICNAME: "使用人",
                //         DICID: "290",
                //         key: "CQRHSYR",
                //         keys: "CQRHSYR",
                //       },
                //     ],
                //   ],
                // },
                // {
                //   name: "委托单位",
                //   key: "WTDW",
                //   XIALA: false,
                //   required: true,
                // },
                {
                    name: "组织名称",
                    key: "WTDW",
                    XIALA: false,
                    disabled: false,
                    required: true,
                },
                {
                    name: "统一社会信用代码",
                    key: "TYSHXYDM",
                    disabled: false,
                    XIALA: false,
                    required: true,
                },
                {
                    name: "经办人姓名",
                    key: "SQR",
                    disabled: false,
                    XIALA: false,
                    required: true,
                },
                {
                    name: "经办人身份证号码",
                    key: "SFZH",
                    disabled: false,
                    XIALA: false,
                    required: true,
                },
                {
                    name: "经办人手机号",
                    key: "PHONE",
                    disabled: false,
                    XIALA: false,
                    required: true,
                },
                {
                    name: "房屋信息",
                    rightName: "请核对您的房屋信息",
                    title: true,
                },
                {
                    name: "所属区域",
                    key: "SSQY",
                    disabled: false,
                    required: true,
                    XIALA: true,
                    keyName: "CITYNAME",
                    keys: "S",
                    actions: [],
                },
                // {
                //   name: "所属市",
                //   key: "SSS",
                //   required: true,
                //   XIALA: true,
                //   keyName: "CITYNAME",
                //   keys: "S",
                //   actions: [],
                // },
                // {
                //   name: "所属县(区)",
                //   key: "SSX",
                //   keyName: "CITYNAME",
                //   XIALA: true,
                //   keys: "X",
                //   actions: [],
                //   required: true,
                // },
                // {
                //   name: "所属镇",
                //   key: "SSZ",
                //   keyName: "CITYNAME",
                //   XIALA: true,
                //   keys: "Z",
                //   actions: [],
                //   required: true,
                // },
                // {
                //   name: "所属村",
                //   key: "SSC",
                //   keyName: "CITYNAME",
                //   XIALA: true,
                //   keys: "C",
                //   actions: [],
                //   required: true,
                // },
                {
                    name: "坐落地址",
                    type: '城镇房屋',
                    key: "ZLDZ",
                    required: true,
                    disabled: false,
                    XIALA: false,
                    title: false,
                    keys: "ZLDZ",
                },
                {
                    name: "项目名称",
                    type: '城镇房屋',
                    disabled: false,
                    key: "XMMC",
                    required: true,
                    XIALA: false,
                    title: false,
                    keys: "XMMC",
                },
                {
                    name: "幢名称",
                    type: '城镇房屋',
                    disabled: false,
                    key: "ZMC",
                    required: true,
                    XIALA: false,
                    title: false,
                    keys: "ZMC",
                },
                {
                    name: "建筑层数",
                    key: "JZCS",
                    disabled: false,
                    required: false,
                    title: false,
                    XIALA: true,
                    keyName: "DICNAME",
                    keys: "JZCS",
                    actions: [],
                },
                {
                    name: "建筑面积",
                    type: '城镇房屋',
                    key: "JZMJ",
                    disabled: false,
                    required: true,
                    XIALA: false,
                    title: false,
                    keys: "JZMJ",
                },
                {
                    name: "结构类型",
                    type: '城镇房屋',
                    disabled: false,
                    key: "JGLX",
                    required: true,
                    XIALA: false,
                    title: false,
                    keys: "JGLX",
                },
                {
                    name: "具体用途",
                    type: '城镇房屋',
                    disabled: false,
                    key: "JTYT",
                    required: true,
                    XIALA: false,
                    title: false,
                    keys: "JTYT",
                },
                // {
                //   name: "房屋地址",
                //   key: "FWDZ",
                //   XIALA: false,
                //   keys: "FWDZ",
                //   required: true,
                // },
                // {
                //   name: "建筑层数",
                //   key: "JZCS",
                //   XIALA: true,
                //   keyName: "DICNAME",
                //   keys: "JZCS",
                //   actions: [],
                //   required: false,
                // },
                // {
                //   name: "建造年份",
                //   key: "JZNF",
                //   XIALA: true,
                //   keyName: "DICNAME",
                //   keys: "JZNF",
                //   actions: [],
                //   required: false,
                // },
                // {
                //   name: "建筑面积",
                //   key: "JZMJ",
                //   XIALA: false,
                //   keys: "JZMJ",
                //   required: true,
                // },
                // {
                //   name: "具体用途",
                //   key: "JTYT",
                //   XIALA: false,
                //   keys: "JTYT",
                //   required: true,
                // },
                {
                    name: "鉴定信息",
                    rightName: "",
                    title: true,
                },
                {
                    name: "鉴定机构",
                    key: "JDJGMC",
                    XIALA: true,
                    required: true,
                },
                {
                    name: "统一社会信用代码",
                    key: "TYSHXYDM",
                    XIALA: false,
                    disabled: false,
                    required: true,
                },
                // {
                //   name: " 委托事由",
                //   rightName: "",
                //   title: true,
                // },
                {
                    name: "委托事由",
                    key: "WTSY",
                    disabled: false,
                    required: true,
                    keyName: "DICNAME",
                    XIALA: true,
                    title: false,
                    keys: "showPickerWT",
                    actions: [],
                },
            ],
            ListDataArr: [{
                "jzwbh": "330114-002-703-0001-0004",
                "jgsj": "2002-03-28",
                "fwdlbm": "330171000065145",
                "buildingid": "59630769",
                "zldz": "杭州经济技术开发区2号大街877号",
                "zmc": "4幢",
                "jzcs": "6",
                "xmmc": "月雅苑小区",
                "jtyt": "住宅",
                "jglx": "混合结构",
                "buildingcode": "59630769",
                "id": "126b8771b12b11ec92346c92bfce0f92",
                "ssqy": "钱塘区",
                "jzmj": "3612.00000000"
            },
            {
                "jzwbh": "330114-002-703-0001-0005",
                "jgsj": "2002-03-28",
                "fwdlbm": "330171000065140",
                "buildingid": "59632568",
                "zldz": "杭州经济技术开发区2号大街877号",
                "zmc": "5幢",
                "jzcs": "7",
                "xmmc": "月雅苑小区",
                "jtyt": "住宅",
                "jglx": "混合结构",
                "buildingcode": "59632568",
                "id": "126c56fbb12b11ec92346c92bfce0f92",
                "ssqy": "钱塘区",
                "jzmj": "2170.00000000"
            },
            {
                "jzwbh": "330114-002-703-0001-0006",
                "jgsj": "2002-03-28",
                "fwdlbm": "330171000065141",
                "buildingid": "59634454",
                "zldz": "杭州经济技术开发区2号大街877号",
                "zmc": "6幢",
                "jzcs": "7",
                "xmmc": "月雅苑小区",
                "jtyt": "住宅",
                "jglx": "混合结构",
                "buildingcode": "59634454",
                "id": "126d65b4b12b11ec92346c92bfce0f92",
                "ssqy": "钱塘区",
                "jzmj": "2017.00000000"
            },
            {
                "jzwbh": "330114-002-703-0001-0007",
                "jgsj": "2002-03-28",
                "fwdlbm": "330171000065136",
                "buildingid": "59635387",
                "zldz": "杭州经济技术开发区2号大街877号",
                "zmc": "7幢",
                "jzcs": "7",
                "xmmc": "月雅苑小区",
                "jtyt": "住宅",
                "jglx": "混合结构",
                "buildingcode": "59635387",
                "id": "126de9fab12b11ec92346c92bfce0f92",
                "ssqy": "钱塘区",
                "jzmj": "1974.00000000"
            },
            {
                "jzwbh": "330114-002-703-0001-0008",
                "jgsj": "2002-03-28",
                "fwdlbm": "330171000065137",
                "buildingid": "59641342",
                "zldz": "杭州经济技术开发区2号大街877号",
                "zmc": "8幢",
                "jzcs": "7",
                "xmmc": "月雅苑小区",
                "jtyt": "住宅",
                "jglx": "混合结构",
                "buildingcode": "59641342",
                "id": "1270890bb12b11ec92346c92bfce0f92",
                "ssqy": "钱塘区",
                "jzmj": "1974.00000000"
            },
            {
                "jzwbh": "330114-002-703-0001-0009",
                "jgsj": "2002-03-28",
                "fwdlbm": "330171000065142",
                "buildingid": "59642866",
                "zldz": "杭州经济技术开发区2号大街877号",
                "zmc": "9幢",
                "jzcs": "7",
                "xmmc": "月雅苑小区",
                "jtyt": "住宅",
                "jglx": "混合结构",
                "buildingcode": "59642866",
                "id": "127105a8b12b11ec92346c92bfce0f92",
                "ssqy": "钱塘区",
                "jzmj": "1960.00000000"
            }],
            ListData1: [
                {
                    name: "所属区域",
                    rightName: "选择",
                    title: true,
                },
                {
                    name: "建筑物编号",
                    key: "JZWBH",
                    required: true,
                    title: false,
                    XIALA: false,
                },
                {
                    type: '城镇房屋',
                    name: "所属区域",
                    key: "SSQY",
                    required: true,
                    title: false,
                    XIALA: true,
                    keyName: "CITYNAME",
                    keys: "S",
                    actions: [],
                },
                {
                    name: "坐落地址",
                    type: '城镇房屋',
                    key: "ZLDZ",
                    required: true,
                    XIALA: false,
                    title: false,
                    keys: "ZLDZ",
                },
                {
                    name: "项目名称",
                    type: '城镇房屋',
                    key: "XMMC",
                    required: true,
                    XIALA: false,
                    title: false,
                    keys: "XMMC",
                },
                {
                    name: "幢名称",
                    type: '城镇房屋',
                    key: "ZMC",
                    required: true,
                    XIALA: false,
                    title: false,
                    keys: "ZMC",
                },
                {
                    name: "建筑层数",
                    key: "JZCS",
                    required: false,
                    title: false,
                    XIALA: true,
                    keyName: "DICNAME",
                    keys: "JZCS",
                    actions: [],
                },
                {
                    name: "建筑面积",
                    type: '城镇房屋',
                    key: "JZMJ",
                    required: true,
                    XIALA: false,
                    title: false,
                    keys: "JZMJ",
                },
                {
                    name: "结构类型",
                    type: '城镇房屋',
                    key: "JGLX",
                    required: true,
                    XIALA: false,
                    title: false,
                    keys: "JGLX",
                },
                {
                    name: "具体用途",
                    type: '城镇房屋',
                    key: "JTYT",
                    required: true,
                    XIALA: false,
                    title: false,
                    keys: "JTYT",
                },
                {
                    name: "鉴定时间",
                    type: '城镇房屋',
                    key: "JDSJ",
                    required: true,
                    XIALA: false,
                    title: false,
                    keys: "JDSJ",
                },
            ],
            rules: {
                SFZH: {
                    required: true,
                    pattern: /^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
                    message: "请填写正确的身份证号",
                    trigger: ["blur", "change"],
                },
                PHONE: {
                    required: true,
                    pattern: /^1((34[0-8])|(8\d{2})|(([35][0-35-9]|4[579]|66|7[35678]|9[1389])\d{1}))\d{7}$/,
                    message: "请填写正确的手机号",
                    trigger: ["blur", "change"],
                },
                SQR: {
                    required: true,
                    min: 2,
                    max: 4,
                    message: "请填写正确的姓名",
                    trigger: ["blur", "change"],
                }
            },
            radio: "",
            switchVal: false,
        };
    },
    methods: {
        close () {
            this.show = false
        },
        async getJdFwxxToJs () {
            let formData = new FormData();
            formData.append('keyText', '')
            //深拷贝
            // const res = await getJdFwxxToJs()
            this.ListDataArr.forEach(item => {
                return this.key2Upper(item)
            })
            this.show = true
        },
        selectData (data) {
            // for (let k in data) {
            //     for (let S in this.model1){
            //         debugger
            //         if(k == S){
            //             this.model1[S] =  data[K]
            //         }
            //     }
            // }
            for (let key in data) {
                if (this.model1.hasOwnProperty(key)) {
                    this.model1[key] = data[key];
                }
                this.ListData.forEach(item => {
                    debugger
                    if (item.key == key) {
                        item['disabled'] = true
                    }
                })

            }
            console.log(this.ListData,'this.ListData')
            //赋值完毕后需要将对应的值变成不可编辑
            this.show = false
        },
        sexSelect (e) {
            this.model1.sex = e.name;
            this.$refs.form1.validateField("sex");
        },
        //获取区县信息
        getXianOpenDataView: async function (data, data1, data2) {
            let time = Date.now();
            const res = await ECAOpenDataView(
                data2,
                JSON.stringify([{ field: "PID", value: data }]),
                time
            );
            this.ListData.forEach((item) => {
                switch (data1) {
                    case "1":
                        if (item.keys == "X") {
                            item.actions = []
                            item.actions.push(res.Data);
                            item.actions[0].forEach((items) => {
                                items.keys = "X";
                                items.key = "SSX";
                                items.dataguid = "24d07248-ba49-4b82-9029-b5eccaff179d";
                            });
                        }
                        break;
                    case "2":
                        if (item.keys == "Z") {
                            item.actions = []
                            item.actions.push(res.Data);
                            item.actions[0].forEach((items) => {
                                items.keys = "Z";
                                items.key = "SSZ";
                                items.dataguid = "d3aaed7c-84ee-4de3-b70e-07fe188cdc8e";
                            });
                        }
                        break;
                    case "3":
                        if (item.keys == "C") {
                            item.actions = []
                            item.actions.push(res.Data);
                            item.actions[0].forEach((items) => {
                                items.keys = "C";
                                items.key = "SSC";
                                items.dataguid = "";
                            });
                        }
                        break;
                }
            });
        },
        change (e) {
            this.NowData = e.value[0].cityname;
            console.log(this.NowData);
        },
        cancel (data) {
            this.XIALADATA[data] = false;
        },
        citycode1 (str) {
            if (str.endsWith("0000000000") || str.indexOf("33000000") > -1) {
                //省
                return "0";
            } else if (str.endsWith("00000000")) {
                return "1";
            } else if (str.endsWith("000000")) {
                return "2";
            } else if (str.endsWith("000")) {
                return "3";
            }
        },
        key2Upper (obj) {
            for (var key in obj) {
                obj[key.toUpperCase()] = obj[key];
                delete (obj[key]);
            }
            return obj;
        },
        confirmData (name) {
            if (name === '所属区域') {
                this.XIALADATA.S = false
                this.getJdFwxxToJs()
            }
            // this.$nextTick(()=>{

            // })

            // alert(1)
            // console.log(this.model1.FWLX)
        },
        confirm (e) {

            if (e.value[0] && e.value[0].CITYCODE) {
                this.model1[e.value[0].key] = e.value[0].CITYNAME;
                this.model2[e.value[0].key] = e.value[0].CITYCODE;
                this.XIALADATA[e.value[0].keys] = false;
                let str = e.value[0].CITYCODE.toString();
                let str1 = this.citycode1(str);
                console.log(str1);
                if (str1 != undefined) {
                    this.getXianOpenDataView(
                        e.value[0].CITYCODE,
                        str1,
                        e.value[0].dataguid
                    );
                }
            } else {
                console.log(e.value[0]);
                this.model1[e.value[0].key] = e.value[0].DICNAME;
                this.model2[e.value[0].key] = e.value[0].DICID;
                this.XIALADATA[e.value[0].keys] = false;
            }
        },
        handlegoto () {
            //将数据存下来
            uni.setStorageSync("listData", this.model1);
            uni.setStorageSync("model2", this.model2);
            //把图片回显
            uni.setStorageSync('photo6', this.fileList6)
            uni.setStorageSync('uuid', this.uuid)
            uni.setStorageSync('photo7', this.fileList7)
            uni.navigateTo({
                url: "/pages/Authentication/Authentication?component=Commissioned",
            });
        },
        clickPreview (url, lists, name) {
            console.log(url, lists, name);
        },
        guid () {
            return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
                /[xy]/g,
                function (c) {
                    var r = (Math.random() * 16) | 0,
                        v = c == "x" ? r : (r & 0x3) | 0x8;
                    return v.toString(16);
                }
            );
        },

        showToast5 (params) {
            this.$refs.uToast.show({
                message: "请上传附件",
                type: "error",
            });
        },
        async insertDataViewListData () {
            let time = Date.now();
            let date = timeFormat(null, 'yyyy-mm-dd hh:MM:ss')
            //注册企业
            let httpData = {
                loginName: uni.getStorageSync('JDGS').tyshxydm,
                idNum: 1,
                phone: 1,
                cityCode: this.model2.SSS,
                qyId: uni.getStorageSync('JDGS').tyshxydm,
                roleType: "99",
                aliasName: uni.getStorageSync('JDGS').qymc,
                userId: uni.getStorageSync('JDGS').tyshxydm
            };
            const res = await getRegister(httpData)
            if (!res.data.token) {
                this.showToast3()
                return
            }
            //将id值放进
            for (let key in this.model2) {
                for (let keys in this.model1) {
                    if (keys == key) {
                        this.model1[keys] = this.model2[key];
                    }
                }
            }
            this.model1.SQRLX = "2";
            if (!this.uuid) {
                this.showToast5();
                return;
            }
            this.model1.ROW_GUID = this.uuid;
            this.model1.WTSJ = date
            this.model1.CREATETIME = date
            this.model1.CREATER_USER_PKID = uni.getStorageSync("userId");
            let strParams = [this.model1];
            let formdata = {
                dataGuid: "55bda5cf-5037-42a7-987e-585d35cd5418",
                strParams: JSON.stringify(strParams),
                time: time,
                viewParameter: {},
            };
            try {
                const res = await ECAinsertDataView(formdata);
                console.log(res);
                if (res.Success) {
                    //先创建流程
                    let data1 = {
                        wfGuid: "{21F63828-EA18-419E-A64E-0B1603D54265}",
                        //生成一个uuid
                        entityRowGuid: this.uuid,
                        time: time,
                        viewParameter: {},
                    };
                    const res1 = await ECAPrepareCreateProcess(data1);
                    //调用ECAPrepareLoadWorkflowScript
                    const res2 = await ECAPrepareLoadWorkflowScript(
                        "-1",
                        time,
                        "{21F63828-EA18-419E-A64E-0B1603D54265}"
                    );
                    let formdata1 = {
                        matterGuid: "",
                        wfGuid: "{21F63828-EA18-419E-A64E-0B1603D54265}",
                        bizGuid: "77015955-abb9-4d69-abdb-62d70b7eca2e",
                        entityRowGuid: this.uuid,
                        time: time,
                        viewParameter: {},
                    };
                    const res3 = await ECAPrepareLoadCreateProcess(formdata1);
                    const res4 = await ECAPrepareLoadWorkflowScript(
                        res3.TaskId,
                        time,
                        "{21F63828-EA18-419E-A64E-0B1603D54265}"
                    );
                    let data3 = {
                        procName: "get_user_by_taskId",
                        dtParams: JSON.stringify([{
                            "i_taskId": res3.TaskId,
                            "i_type": 0
                        }]),
                    }
                    const user = await ECAExecProcedure(data3)
                    let data2 = {
                        taskId: res3.TaskId,
                        direction: 0,
                        wfBoxGuid: "77015955-abb9-4d69-abdb-62d70b7eca2e",
                        actionText: "",
                        taskName: "",
                        wfGuid: "{21F63828-EA18-419E-A64E-0B1603D54265}",
                        sendNodes: JSON.stringify([
                            {
                                TNID: 116,
                                PTNID: 1,
                                TEXT: user.Data[0]._USERNAME,
                                WFNODEGUID: "{C598953F-7F23-4E8D-AA5B-7B68C71797E8}",
                                WFNODETYPE: 2,
                                WFNODENAME: "鉴定机构",
                                ISUSER: 1,
                                USERID: user.Data[0]._USERID,
                                USERNAME: user.Data[0]._USERNAME,
                                SINGLEASSIGN: true,
                                PREJUNCNODEGUID: "",
                                SORTNUM: 0,
                                selected: true,
                            },
                        ]),
                        time,
                    };
                    //拿到takid
                    const res5 = await ECAPlatSendTask(data2);
                    if (res5.Success) {
                        this.showToast1();
                        setTimeout(() => {
                            this.$nextTick(() => {
                                uni.navigateTo({
                                    url: "/",
                                    animationType: "fade-in",
                                });
                            });
                        }, 1000);
                    } else {
                        this.model1 = uni.getStorageSync("model1");
                        this.showToast3();
                    }
                }
            } catch (err) {
                this.model1 = uni.getStorageSync("model1");
                this.showToast3();
            }
        },
        handleGotonext () {
            let num = 0;
            this.ListData.forEach((item) => {
                if (item.required) {
                    this.model1[item.key] ? "" : (num = num + 1);
                }
            });
            if (num == 0) {
                this.insertDataViewListData();
            } else {
                this.showToast();
            }
        },
        showToast (params) {
            this.$refs.uToast.show({
                message: "请填写必填项",
                type: "error",
            });
        },
        getenumerationData: async function (data = []) {
            //formData参数
            data = qs.parse(data);
            for (let item in data) {
                let time = Date.now();
                const res = await ECAOpenDataView(data[item], JSON.stringify([]), time);
                console.log(res);
                switch (data[item]) {
                    case "e9c98787-4966-4365-80b0-c1cc678c6f85":
                        //市
                        this.ListData.forEach((item) => {
                            if (item.keys == "S") {
                                item.actions.push(res.Data);
                                item.actions[0].forEach((item) => {
                                    item.keys = "S";
                                    item.key = "SSS";
                                    item.dataguid = "77fdf2b0-0eb5-4243-a0a4-6185299ccd34";
                                });
                            }
                        });
                        break;
                    case "77fdf2b0-0eb5-4243-a0a4-6185299ccd34":
                        //镇
                        break;
                    case "24d07248-ba49-4b82-9029-b5eccaff179d":
                        //村
                        break;
                    case "30c64dd9-9db2-4d30-ad8f-62d219de2325":
                        //事件委托
                        this.ListData.forEach((items) => {
                            if (items.name == "委托事由") {
                                items.actions.push(res.Data);
                                items.actions[0].forEach((item) => {
                                    item.keys = "showPickerWT";
                                    item.key = "WTSY";
                                });
                            }
                        });
                        break;
                    case "bcc29049-e7a8-450c-b40e-e4cd2e600cb9":
                        //建筑层数
                        this.ListData.forEach((items) => {
                            if (items.name == "建筑层数") {
                                items.actions.push(res.Data);
                                items.actions[0].forEach((item) => {
                                    item.keys = "JZCS";
                                    item.key = "JZCS";
                                });
                            }
                        });
                        break;
                    case "5606ea58-5e29-470d-8d99-2a936585ad99":
                        //建造年份
                        this.ListData.forEach((items) => {
                            if (items.name == "建造年份") {
                                items.actions.push(res.Data);
                                items.actions[0].forEach((item) => {
                                    item.keys = "JZNF";
                                    item.key = "JZNF";
                                });
                            }
                        });
                        break;
                    case "24d07248-ba49-4b82-9029-b5eccaff179d":
                        //村
                        break;
                }
            }
        },

        //将blob转换成file
        blobToFile (theBlob, fileName) {
            theBlob.lastModifiedDate = new Date();
            theBlob.name = fileName;
            return theBlob;
        },
        // 删除图片
        deletePic (event) {
            this[`fileList${event.name}`].splice(event.index, 1);
        },
        // 删除图片
        deletePic1 (event) {
            this[`fileList${event.name}`].splice(event.index, 1);
        },
        // 新增图片
        async afterRead (event) {
            console.log(event);
            // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
            let lists = [].concat(event.file);
            let fileListLen = this[`fileList${event.name}`].length;
            lists.map((item) => {
                this[`fileList${event.name}`].push({
                    ...item,
                    status: "uploading",
                    message: "上传中",
                });
            });
            for (let i = 0; i < lists.length; i++) {
                const result = await this.uploadFilePromise(lists[i].url);
                console.log(this[`fileList${event.name}`]);
                let item = this[`fileList${event.name}`][fileListLen];
                this[`fileList${event.name}`].splice(
                    fileListLen,
                    1,
                    Object.assign(item, {
                        status: "success",
                        message: "",
                        url: result,
                    })
                );
                console.log(this[`fileList${event.name}`]);
                fileListLen++;
            }
        },
        async uploadFilePromise (file) {
            this.uuid = this.guid();
            return new Promise((resolve, reject) => {
                let a = uni.uploadFile({
                    url:
                        "https://nfzjszlb.jst.zj.gov.cn/eca/fwjd/FileServer/api/Upload?token=" +
                        uni.getStorageSync("token"), // 仅为示例，非真实的接口地址
                    filePath: file,
                    name: "file",
                    formData: {
                        toRowGuid: this.uuid,
                        groupGuid: "19902700-f952-4561-a338-5590056dab65",
                        token: uni.getStorageSync("token"),
                    },
                    success: (res) => {
                        setTimeout(() => {
                            this.showToast4();
                            resolve(res);
                        }, 1000);
                    },
                });
            });
        },
        // 新增图片
        async afterRead1 (event) {
            console.log(event);
            // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
            let lists = [].concat(event.file);
            let fileListLen = this[`fileList${event.name}`].length;
            lists.map((item) => {
                this[`fileList${event.name}`].push({
                    ...item,
                    status: "uploading",
                    message: "上传中",
                });
            });
            for (let i = 0; i < lists.length; i++) {
                const result = await this.uploadFilePromise1(lists[i].url);
                let item = this[`fileList${event.name}`][fileListLen];
                this[`fileList${event.name}`].splice(
                    fileListLen,
                    1,
                    Object.assign(item, {
                        status: "success",
                        message: "",
                        url: result,
                    })
                );
                fileListLen++;
            }
        },
        async uploadFilePromise1 (file) {
            // let files = new window.File([file], file.name, { type: file.type });
            // let formData = new FormData();
            // formData.append("file", files);
            // formData.append("token", uni.getStorageSync("token"));
            // formData.append("toRowGuid", "");
            // formData.append("groupGuid", "19902700-f952-4561-a338-5590056dab65");
            // formData.forEach((value) => console.log(value));
            // const res = await ECAFileServerUpload(formData);
            // let data1 = res.FileList;
            // this.fileGuid = data1[0].FILEGUID;
            // if (data1[0].FILEGUID) {
            // }
            this.uuid = this.guid();
            return new Promise((resolve, reject) => {
                let a = uni.uploadFile({
                    url:
                        "https://nfzjszlb.jst.zj.gov.cn/eca/fwjd/FileServer/api/Upload?token=" +
                        uni.getStorageSync("token"), // 仅为示例，非真实的接口地址
                    filePath: file,
                    name: "file",
                    formData: {
                        toRowGuid: this.uuid,
                        groupGuid: "d26fd8fd-0d8a-46ec-af9f-2341ba78fb58",
                        token: uni.getStorageSync("token"),
                    },
                    success: (res) => {
                        setTimeout(() => {
                            this.showToast4();
                            resolve(res);
                        }, 1000);
                    },
                });
            });
        },
        showToast4 (params) {
            this.$refs.uToast.show({
                message: "上传成功",
                type: "success",
            });
        },
        showToast3 (params) {
            this.$refs.uToast.show({
                message: "提交失败",
                type: "error",
            });
        },
        showToast1 (params) {
            this.$refs.uToast.show({
                message: "发送成功",
                type: "success",
            });
        },
    },
    onLoad (options) {
        // this.getXianOpenDataView("330000000000", "0");
        //获取枚举数据
        let data1 = [
            "77fdf2b0-0eb5-4243-a0a4-6185299ccd34",
            "e9c98787-4966-4365-80b0-c1cc678c6f85",
            "24d07248-ba49-4b82-9029-b5eccaff179d",
            "30c64dd9-9db2-4d30-ad8f-62d219de2325",
            "bcc29049-e7a8-450c-b40e-e4cd2e600cb9",
            "5606ea58-5e29-470d-8d99-2a936585ad99",
        ];
        this.getenumerationData(qs.stringify(data1));
        this.ISIphone = isIphoneX();
        uni.$on("details", (data) => {
            this.model1 = uni.getStorageSync("listData");
            this.model2 = uni.getStorageSync("model2");
            this.fileList6 = uni.getStorageSync("photo6")
            this.fileList7 = uni.getStorageSync("photo7")
            this.uuid = uni.getStorageSync("uuid")
            this.model1.JDJGMC = uni.getStorageSync('JDGS').qymc;
            this.model1.TYSHXYDM = uni.getStorageSync('JDGS').tyshxydm;
        });
        if (ZWJSBridge) {
            ZWJSBridge.setTitle({
                title: "单位委托",
            })
                .then((res) => { })
                .catch((err) => { });
        }
    },
    onUnload () {
        uni.$off("details");
    },
};
</script>


<style lang="scss" scoped>
.Commissioned {
    overflow: auto;

    .title {
        padding: 0.6rem 0;
        font-size: 1.1rem;
        font-weight: 800;
    }

    .list {
        padding: 1rem;
    }

    .footer {
        padding-top: 0.6rem;
        text-align: center;

        span {
            font-size: 14px;
            color: #007aff;
            margin-bottom: 1rem;
        }
    }

    .top {
        height: 30px;
        background: #ffffff;
        margin-bottom: 15px;
        padding-top: 15px;
        text-align: center;

        .origin {
            width: 22px;
            height: 22px;
            background: #007aff;
            border-radius: 50%;
            display: inline-block;
        }

        .line {
            width: 20vw;
            /*height: 1px;*/
            border: 1px dashed #007aff;
            display: inline-block;
        }
    }

    .backgrounds {
        height: 1rem;
        background: #eee;
    }

    .u-upload__wrap__preview__image[data-v-69e2a36e] {
        width: 166px !important;
        height: 100px !important;
    }
}
</style>

<style>
::v-deep .u-form-item__body__left__content__label{
    min-width: 200px !important;
}
.uni-input-input, .uni-input-placeholder{
    text-align: right !important;
}
::v-deep .uni-input-input{
    text-align: right !important;
}
</style>